package com.atguigu.lease.common.minio;

import io.minio.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * @author Marco
 * @Description    因为 后台管理端和 用户端都需要上传 房间图片和 头像，所以
 *   在 当前 模块中直接  创建  MinioClient 对象
 * @date 2025/7/27 13:17
 * @email 3293336923@qq.com
 */
@Configuration
@ConditionalOnProperty(name = "minio.endpoint")  //  当   minio.endpoint 有值 ，当前这个配置类才会生效
@EnableConfigurationProperties(MinioProperties.class)
public class MinioConfiguration {

    @Autowired
    private MinioProperties minioProperties;

    @Bean
    public MinioClient minioClient() {

        return MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(
                             minioProperties.getAccessKey(),
                             minioProperties.getSecretKey()
                            )
                .build();


//        return   MinioClient.builder()
//                .endpoint(minioProperties.getEndPoint())
//                .credentials(minioProperties.getAccessKey(), minioProperties.getAccessSecret())
//                .build();
    }
}
